#include "ItemData.h"




void ItemData::_initDirection()
{
	double x = rect->X;
	double targetx = _targetRect->X;

	if (x < targetx) {
		_direction = 1;
	} else {
		_direction = -1;
	}
}

ItemData::ItemData(int id, int itemType, double x, double y, Rect* targetRect)
{
	this->type = itemType;
	this->_itemType = itemType;
	this->itemRandom = rand() % 6 + 501;
	this->id = id;		
	this->rect = new Rect(x, y, _ITEM_HEIGHT, _ITEM_WIDTH);
	this->_baseY = y;
	this->_targetRect = targetRect;

	this->counter = 0.1;
	this->rangeOfEffect = 800;
	this->isActived = false;
	this->canInteract = true;

	initSprite();
	_initDirection();
}

Rect* ItemData::getTargetRect()
{
	return _targetRect;
}

void ItemData::setState(ItemBlockStates state)
{
	this->stateitem = state;
}

double ItemData::getBaseY()
{
	return _baseY;
}

int ItemData::getDirection()
{
	return _direction;
}

void ItemData::initSprite()
{
	initSpriteHandler();

	sprites->addSprite(1, this->_itemType, 8);
	sprites->setState(1);
}

void ItemData::initSpriteHandler()
{
	sprites = new Sprites(this->rect);
	sprites->initSpriteHandler(*(GameDeviceSingleton::getInstance()->getSpriteHandler()));
}

void ItemData::initSpriteHandler(LPD3DXSPRITE spriteHandler)
{
	sprites->initSpriteHandler(spriteHandler);
}

int ItemData::getItemType()
{
	return _itemType;
}
